//
//  ShareViewController.m
//  FNMenu
//
//  Created by 航汇聚科技 on 2018/9/17.
//  Copyright © 2018年 Yi Zhou. All rights reserved.
//

#import "ShareViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "NSDictionary+Safety.h"
#import "ShareManager.h"
@interface ShareViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *shareBackgroundImgView;
@property (weak, nonatomic) IBOutlet UILabel *shareTitleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *shareCodeImgVIew;

@end

@implementation ShareViewController

+ (instancetype)shareVCFromStoryBoard {
    return [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ShareVC"];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
#pragma mark - lifeCycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.shareBackgroundImgView.userInteractionEnabled = YES;
    self.shareTitleLabel.text = [_info safeObjectForKey:@"title"];
    [self.shareCodeImgVIew sd_setImageWithURL:[NSURL URLWithString:[_info safeObjectForKey:@"codeIconAddress"]]];
}


#pragma mark - event response
- (IBAction)dismissAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)shareAction:(UIButton *)sender {
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession), @(UMSocialPlatformType_WechatTimeLine)]];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        NSMutableDictionary *shareInfo = [@{} mutableCopy];
        [shareInfo setSafeValue:[self.info safeObjectForKey:@"thumImage"] forKey:shareThumbImgStr];
        [shareInfo setSafeValue:[self.info safeObjectForKey:@"title"] forKey:shareTitle];
        [shareInfo setSafeValue:[self.info safeObjectForKey:@"descr"] forKey:shareDescr];
        [shareInfo setSafeValue:[self.info safeObjectForKey:@"webpageUrl"] forKey:shareWebPageURL];
        [ShareManager shareWebPageToPlatformType:platformType shareInfo:shareInfo success:^{
            
        } failure:^(NSString * _Nonnull msg) {
            
        }];
    }];
}

#pragma mark - setter
- (void)setInfo:(NSDictionary *)info {
    _info = info;
}

@end
